<?php

namespace App\Services;

use App\Traits\Config;
use Illuminate\Console\Command;

class BaseService
{

    use Config;
    // \$this->errMsg\s*=\s*(.*);

    public $errMsg = '';
    private $command = null;

    public function getErrMsg()
    {
        return trim($this->errMsg, '|');
    }

    public function setCommand(Command $command)
    {
        $this->command = $command;
        return $this;
    }

    public function error(string $msg)
    {
        if (is_null($this->command)) {
            $this->errMsg .= $msg . '|';
        } else {
            $this->command->error($msg);
        }
        return $this;
    }

    public function line(string $msg)
    {
        if (!is_null($this->command)) {
            $this->command->line($msg);
        }
        return $this;
    }


    public function initErr()
    {
        $this->errMsg = '';
        return $this;
    }

    public function returnFalse()
    {
        return false;
    }
}
